package com.panda.system.service.impl;

import com.panda.common.annotation.DataScope;
import com.panda.common.utils.DateUtils;
import com.panda.common.utils.DictUtils;
import com.panda.system.domain.TPandaRebatesTask;
import com.panda.system.mapper.TPandaRebatesTaskMapper;
import com.panda.system.service.ITPandaRebatesTaskService;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 返款任务看板Service业务层处理
 * 
 * @author panda
 * @date 2021-02-28
 */
@Service
public class TPandaRebatesTaskServiceImpl implements ITPandaRebatesTaskService 
{
    private static final Logger log = LoggerFactory.getLogger(TPandaRebatesTaskServiceImpl.class);
    @Autowired
    private TPandaRebatesTaskMapper tPandaRebatesTaskMapper;

    /**
     * 查询返款任务看板
     * 
     * @param id 返款任务看板ID
     * @return 返款任务看板
     */
    @Override
    public TPandaRebatesTask selectTPandaRebatesTaskById(Long id)
    {
        return tPandaRebatesTaskMapper.selectTPandaRebatesTaskById(id);
    }

    /**
     * 查询返款任务看板列表
     * 
     * @param tPandaRebatesTask 返款任务看板
     * @return 返款任务看板
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<TPandaRebatesTask> selectTPandaRebatesTaskList(TPandaRebatesTask tPandaRebatesTask)
    {
        List<TPandaRebatesTask> tPandaRebatesTasks = tPandaRebatesTaskMapper.selectTPandaRebatesTaskList(tPandaRebatesTask);
        for(TPandaRebatesTask item:tPandaRebatesTasks){
            // 翻译
            item.setStatusShow(DictUtils.getDictLabel("rebates_task_status", item.getStatus()));
            item.setBuyerTypeShow(DictUtils.getDictLabel("user_type", item.getBuyerType()));
            item.setOrderTypeShow(DictUtils.getDictLabel("order_type", item.getOrderType()));
            item.setRebatesChannelShow(DictUtils.getDictLabel("channel_type", item.getRebatesChannel()));
            item.setTradingTypeShow(DictUtils.getDictLabel("trading_type", item.getTradingType()));
            item.setIntegration(true);
            // 是否集成判断
            if(!Strings.isNotEmpty(item.getSecret())||item.getSecret().length()<32){
                item.setIntegration(false);
            }
        }
        return tPandaRebatesTasks;
    }

    /**
     * 查询返款任务看板列表
     *
     * @param tPandaRebatesTask 返款任务看板
     * @return 返款任务看板
     */
    @Override
    public List<TPandaRebatesTask> selectTPandaRebatesTaskListSys(TPandaRebatesTask tPandaRebatesTask)
    {
        return tPandaRebatesTaskMapper.selectTPandaRebatesTaskListSys(tPandaRebatesTask);
    }

    /**
     * 新增返款任务看板
     * 
     * @param tPandaRebatesTask 返款任务看板
     * @return 结果
     */
    @Override
    public long insertTPandaRebatesTask(TPandaRebatesTask tPandaRebatesTask)
    {
        tPandaRebatesTask.setCreateTime(DateUtils.getNowDate());
        long id = tPandaRebatesTaskMapper.insertTPandaRebatesTask(tPandaRebatesTask);
        return tPandaRebatesTask.getId();
    }

    /**
     * 修改返款任务看板
     * 
     * @param tPandaRebatesTask 返款任务看板
     * @return 结果
     */
    @Override
    public int updateTPandaRebatesTask(TPandaRebatesTask tPandaRebatesTask)
    {
        tPandaRebatesTask.setUpdateTime(DateUtils.getNowDate());
        return tPandaRebatesTaskMapper.updateTPandaRebatesTask(tPandaRebatesTask);
    }

    /**
     * 批量删除返款任务看板
     * 
     * @param ids 需要删除的返款任务看板ID
     * @return 结果
     */
    @Override
    public int deleteTPandaRebatesTaskByIds(Long[] ids)
    {
        return tPandaRebatesTaskMapper.deleteTPandaRebatesTaskByIds(ids);
    }

    /**
     * 删除返款任务看板信息
     * 
     * @param id 返款任务看板ID
     * @return 结果
     */
    @Override
    public int deleteTPandaRebatesTaskById(Long id)
    {
        return tPandaRebatesTaskMapper.deleteTPandaRebatesTaskById(id);
    }
}
